#pragma once

class Base;
#include <map>
#include <audiere.h>


// a simple sound engine for general game engines.
// wrapped by HPFDF <hpfdf@126.com>
// powered by audiere

class Sounder
{
private:
	audiere::AudioDevicePtr device;
	Base* parent;
	float music_vol;
	float fx_vol;

	struct Stream
	{
		float vol_mask, pitch_mask, pan_offset;
		audiere::OutputStreamPtr stream;
		bool is_fx;
		Stream();
		Stream(Sounder* par,
			   std::string dir,
			   bool is_fx,
			   float vol_mask,
			   float pitch_mask,
			   float pan_offset);
	};

	// use a name->stream map to manage sound streams for the game.
	std::map<std::string, Stream> streams;

public:

	// basic and simple initialize and finalize process
	Sounder();
	~Sounder();

	// custom init, can pre-load some streams here
	virtual void init(Base* parent);
	
	audiere::AudioDevicePtr get_device();

	void load_stream(std::string name, std::string dir,
					 bool is_fx = true,
		             float vol_mask = 1.f,
					 float pitch_mask = 1.f,
					 float pan_offset = 0.f);

	void remove_stream(std::string name);

	void remove_all_stream();

	void play_once(std::string name, float from = 0.f, float to = 1.f);
	void play_repeat(std::string name, float from = 0.f, float to = 1.f);

	void stop(std::string name);
	void stop_all();
	
	void set_pitch(std::string name, float pitch);
	void set_pan(std::string name, float pan);

	void update_all_vol(bool is_fx);

	float get_music_vol();
	float get_fx_vol();
	
	void set_music_vol(float ratio = 1.f);
	void set_fx_vol(float ratio = 1.f);
};
